<template>
    <div class="app-container">
        <el-form v-show="showSearch" ref="queryParamsRef" :inline="true" :model="queryParams" label-width="80px">
            <el-form-item v-if="!userInfo.orgId">
                <select-org-tree :value="queryParams.orgId" @orgNodeClick="orgNodeClick" />
            </el-form-item>
            <el-form-item label="药品代码" prop="drugCode">
                <el-input v-model="queryParams.drugCode" clearable placeholder="请输入药品代码"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="药品名称" prop="drugName">
                <el-input v-model="queryParams.drugName" clearable placeholder="请输入药品名称"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="操作类型" prop="operationType">
                <el-select class="width-120" v-model="queryParams.operationType" clearable placeholder="请选择操作类型">
                    <el-option v-for="dict in dictDataMap['price_operation_type']" :key="dict.value" :label="dict.label"
                        :value="dict.value" />
                </el-select>
            </el-form-item>
            <div style="float: right" class="mr20">
                <query-form-button @handleQuery="handleQuery" @resetQuery="resetQuery" />
            </div>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button v-hasPerm="['base:drugPriceLog:export']" plain type="warning" @click="handleExport"><template
                        #icon>
                        <i-ep-download />
                    </template>导出
                </el-button>
            </el-col>
        </el-row>

        <el-table v-adaptive :data="drugPriceLogList" :border="true" highlight-current-row
            :header-cell-style="$headerCellStyle" :stripe="true">
            <el-table-column :show-overflow-tooltip="true" :align="'center'" label="药品代码" prop="drugCode"
                width="180px" />
            <el-table-column :show-overflow-tooltip="true" :align="'center'" label="药品名称" prop="drugName"
                width="180px" />
            <el-table-column :show-overflow-tooltip="true" :align="'center'" label="包装规格" prop="packageSpec" />
            <el-table-column :show-overflow-tooltip="true" :align="'center'" label="药品单位" prop="units">
                <template #default="scope">
                    <dict-data-tag :options="dictDataMap['dose_unit']" :value="scope.row.units" />
                </template>
            </el-table-column>
            <el-table-column :show-overflow-tooltip="true" :align="'center'" label="进价" prop="tradePrice" />
            <el-table-column :show-overflow-tooltip="true" :align="'center'" label="市场零售价" prop="retailPrice" />
            <el-table-column :show-overflow-tooltip="true" :align="'center'" label="门诊费用分类" min-width="100px"
                prop="classOnRcpt">
                <template #default="scope">
                    <dict-data-tag :options="dictDataMap['outp_rcpt_fee_dict']" :value="scope.row.classOnRcpt" />
                </template>
            </el-table-column>
            <el-table-column :show-overflow-tooltip="true" :align="'center'" label="住院费用分类" min-width="100px"
                prop="classOnInp">
                <template #default="scope">
                    <dict-data-tag :options="dictDataMap['inp_rcpt_fee_dict']" :value="scope.row.classOnInp" />
                </template>
            </el-table-column>
            <el-table-column :show-overflow-tooltip="true" :align="'center'" label="核算项目分类" min-width="100px"
                prop="classOnReckoning">
                <template #default="scope">
                    <dict-data-tag :options="dictDataMap['reck_item_class_dict']" :value="scope.row.classOnReckoning" />
                </template>
            </el-table-column>
            <el-table-column :show-overflow-tooltip="true" :align="'center'" label="会计科目" min-width="100px"
                prop="subjCode">
                <template #default="scope">
                    <dict-data-tag :options="dictDataMap['tally_subject_dict']" :value="scope.row.subjCode" />
                </template>
            </el-table-column>
            <el-table-column :show-overflow-tooltip="true" :align="'center'" label="病案首页分类" min-width="100px"
                prop="classOnMr">
                <template #default="scope">
                    <dict-data-tag :options="dictDataMap['mr_fee_class_dict']" :value="scope.row.classOnMr" />
                </template>
            </el-table-column>
            <el-table-column :align="'center'" label="开始时间" prop="startDate" width="160">
                <template #default="scope">
                    <span>{{ $parseTime(scope.row.startDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                </template>
            </el-table-column>
            <el-table-column :align="'center'" label="停止时间" prop="stopDate" width="160">
                <template #default="scope">
                    <span>{{ $parseTime(scope.row.stopDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                </template>
            </el-table-column>
            <el-table-column :align="'center'" label="操作类型" prop="operationType">
                <template #default="scope">
                    <dict-data-tag :options="dictDataMap['price_operation_type']" :value="scope.row.operationType" />
                </template>
            </el-table-column>
            <el-table-column :align="'center'" label="操作时间" prop="createTime" width="180">
                <template #default="scope">
                    <span>{{ $parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                </template>
            </el-table-column>
            <el-table-column :show-overflow-tooltip="true" :align="'left'" label="操作人" prop="createBy" />
            <el-table-column :show-overflow-tooltip="true" :align="'center'" label="是否最新价格" min-width="100px"
                prop="isNew">
                <template #default="scope">
                    <dict-data-tag :options="dictDataMap['is_new']" :value="scope.row.isNew" />
                </template>
            </el-table-column>
            <el-table-column :show-overflow-tooltip="true" :align="'center'" label="备注信息" prop="remarks" />
            <el-table-column :show-overflow-tooltip="true" :align="'center'" label="比例" prop="ratio" />
        </el-table>
        <pagination v-show="total > 0" v-model:limit="queryParams.pageSize" v-model:page="queryParams.pageNum"
            :total="total" @pagination="getList" />
    </div>
</template>

<script lang="ts" setup>
import {selectPageDrugPriceLog} from "@/api/drug/drugPriceLog";

import {useUserStoreHook} from "@/store/modules/user";
import {useDictStoreHook} from "@/store/modules/dict";

const useUserStore = useUserStoreHook();
const { proxy } = getCurrentInstance() as any
const dictStore = useDictStoreHook();
const dictDataMap = ref(dictStore.isTypeGetData('dose_unit', 'tally_subject_dict', 'bill_item_class_dict', 'outp_rcpt_fee_dict', 'inp_rcpt_fee_dict',
    'reck_item_class_dict', 'mr_fee_class_dict', 'spec_unit', 'is_medical_insurance', 'price_operation_type', 'is_new'))
// 登录用户信息
const userInfo = <UserInfoBusi>useUserStore.user.userInfo
const queryParamsRef = ref()
// 选中数组
const ids = ref<any>([])
// 非单个禁用
const single = ref(true)
// 非多个禁用
const multiple = ref(true)
// 显示搜索条件
const showSearch = ref(true)
// 总条数
const total = ref(0)
// base表格数据
const drugPriceLogList = ref<any>([])

// 查询参数
const queryParams = ref<any>({
    pageNum: 1,
    pageSize: 10,
    drugInfo: undefined,
    durgPriceId: undefined,
    medicalInsuranceType: undefined,
    priceId: undefined,
    packageSpec: undefined,
    units: undefined,
    networkPrice: undefined,
    tradePrice: undefined,
    retailPrice: undefined,
    startDate: undefined,
    stopDate: undefined,
    classOnRcpt: undefined,
    classOnInp: undefined,
    classOnReckoning: undefined,
    subjCode: undefined,
    classOnMr: undefined,
    priceMax: undefined,
    isNew: undefined,
    orgId: undefined,
    remarks: undefined,
    ratio: undefined,
    operationType: undefined,
    drugCode: undefined,
    drugName: undefined
})

if (userInfo.orgId) {
    queryParams.value.orgId = userInfo.orgId
    getList()
}
// 机构树点击事件
function orgNodeClick(data, _e) {
    queryParams.value.orgId = data.orgId
    if (queryParams.value.orgId) {
        getList()
    }
}
/** 查询base列表 */
function getList() {
    selectPageDrugPriceLog(queryParams.value).then((response: any) => {
        drugPriceLogList.value = response.rows;
        total.value = response.total;
    });
}
/** 搜索按钮操作 */
function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
}
/** 重置按钮操作 */
function resetQuery() {
    queryParamsRef.value.resetFields()
    handleQuery();
}
/** 导出按钮操作 */
function handleExport() {
    // download('base/drugPriceLog/export', {
    //     ...queryParams
    // }, `drugPriceLog${new Date().getTime()}.xlsx`)
}
</script>
<script lang="ts">
export default {
    name: "DrugPriceLog"
}
</script>

<style scoped>
:deep(.vue-treeselect__control) {
    height: 30px !important;
    margin-bottom: 13px;
}

:deep(.vue-treeselect__single-value) {
    top: -2px
}
</style>
